package com.huobao.yunying.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.huobao.yunying.entity.TemaiDetail_goods_list;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import java.util.List;

import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Temai_Detail_GridView extends QuickAdapter<TemaiDetail_goods_list> {

	public Adapter_Temai_Detail_GridView(Context context, List<TemaiDetail_goods_list> data) {
		super(context, R.layout.item_temai_detail_grid, data);
	}

	@Override
	protected void convert(BaseAdapterHelper helper, TemaiDetail_goods_list arg1) {
		final ImageView imageView = helper.getView(R.id.imageview);
		TextView tv_title = helper.getView(R.id.tv_title);
		TextView qianggou = helper.getView(R.id.btn_1);
		TextView tv_name = helper.getView(R.id.tv_name);
		ImageUtils.loadimg(imageView, arg1.getDefault_image(), new OnImageLoadListener() {

			@Override
			public void onLoadSuccess(Drawable drawable) {
				int newWidth = ScreenUtil.getInstant().getDisWidth(context) / 2 - 20;
				int newHight = newWidth * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth();
				LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
				layoutParams.width = newWidth;
				layoutParams.height = newHight;
				imageView.setLayoutParams(layoutParams);
				notifyDataSetChanged();
			}
		});
		if (arg1.getGenre().equals("1") || arg1.getGenre().equals("2"))
			tv_title.setText("￥" + arg1.getPrice());
		else if (arg1.getGenre().equals("3"))
			tv_title.setText(arg1.getSzhaoshang());
		qianggou.setText(arg1.getStext());
		tv_name.setVisibility(View.VISIBLE);
		tv_name.setText(arg1.getGoods_name());
	}

}
